package com.orangelife.mobile.pay.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.common.sp.PaySp;
import com.curry.orangelife.mobile.R;

/**
 * <p>
 * Created by 吴格非 on 2017-1-4.
 * <p>
 *
 * @author 吴格非
 * @since v1.0.0
 */

public class PayPwdSetTipDialog extends Dialog {
    private Context context;

    public PayPwdSetTipDialog(Context context) {
        super(context, R.style.NewDialogStyle);
        this.context = context;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        setAttr();
    }

    public void initView() {
        LayoutInflater inflater = LayoutInflater.from(this.context);
        View view = inflater.inflate(R.layout.dialog_pay_pwd_set_tip, null);
        this.setContentView(view);
        TextView tvSetNow = (TextView) findViewById(R.id.tvSetNow);
        TextView tvNextTime = (TextView) findViewById(R.id.tvNextTime);
        TextView tvNever = (TextView) findViewById(R.id.tvNever);
        tvSetNow.setOnClickListener(listener);
        tvNextTime.setOnClickListener(listener);
        tvNever.setOnClickListener(listener);
        setCanceledOnTouchOutside(false);
    }

    View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tvSetNow:
                    showPayPwd();
                    break;
                case R.id.tvNextTime:
                    dismiss();
                    break;
                case R.id.tvNever:
                    PaySp.setNeverSetPayPwd(true);
                    dismiss();
                    break;
            }
        }
    };

    private void showPayPwd() {
        PayPwdDialog ppd = new PayPwdDialog(context, true);
        ppd.show();
        ppd.showKeyboard();
        dismiss();
    }

    private void setAttr() {
        Window dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = this.context.getResources().getDisplayMetrics();
        lp.width = (int) ((double) d.widthPixels * 0.7D);
        dialogWindow.setAttributes(lp);
    }
}
